home *** CD-ROM | disk | FTP | other *** search
- (*===========================================================================*)
- (* X/Ymodem Protocol processor -- Main line *)
- (* *)
- (* Copyright 1989 by H. Roy Engehausen. All rights reserved. *)
- (* *)
- (*===========================================================================*)
-
- PROCEDURE xy_xfer;
-
- CONST
- nul = #0;
- soh = #1;
- stx = #2;
- etx = #3;
- eot = #4;
- enq = #5;
- ack = #6;
- dle = #16;
- nak = #21;
- can = #24;
- eof = #26;
-
- small_buff_size = 10;
-
- TYPE
- buff_tail = RECORD
- CASE BYTE OF
- 0: (xy_chksum : BYTE);
- 1: (xy_crc_hi : BYTE;
- xy_crc_lo : BYTE);
- END;
-
- buff_type = RECORD
- xy_type : CHAR;
- xy_b_no : BYTE;
- xy_b_no_invert : BYTE;
- CASE BYTE OF
- 0: (x_b : ARRAY[1..128] OF CHAR;
- x_tail : buff_tail);
- 1: (y_b : ARRAY[1..1024] OF CHAR;
- y_tail : buff_tail);
- END;
-
- buff_ptr = ^buff_type;
-
- VAR
- b_size : WORD;
- batch_sw : BOOLEAN;
- big_buff : buff_ptr;
- block_no : BYTE;
- block_type : CHAR;
- check_num : WORD;
- crc_sw : BOOLEAN;
- curr_size : LONGINT;
- data_file : ^FILE;
- error_cnt : BYTE;
- first_sw : BOOLEAN;
- file_size : LONGINT;
- header_str : STRING[128];
- small_buff : buff_ptr;
- tail_ptr : ^buff_tail;
- time_to_wait : WORD;
- to_sw : BOOLEAN;
- ymodem_sw : BOOLEAN;
-
- {$I BBXYMODC.PAS}
- {$I BBXYMODU.PAS}
- {$I BBXYMODD.PAS}
-
- BEGIN;
-
- (*-----------------------------------------------------------------------*)
- (* Locate the file area *)
- (*-----------------------------------------------------------------------*)
-
- data_file := @active_tcb^.io_fe^.fe_bin;
-
- (*-----------------------------------------------------------------------*)
- (* Ready the data file *)
- (*-----------------------------------------------------------------------*)
-
- assign(data_file^, pkfname);
-
- (*-----------------------------------------------------------------------*)
- (* Get the buffer area *)
- (*-----------------------------------------------------------------------*)
-
- big_buff := get_task_mem('BIN', SIZEOF(buff_type));
-
- small_buff := get_task_mem('BIN', small_buff_size);
-
- (*-----------------------------------------------------------------------*)
- (* Ready things *)
- (*-----------------------------------------------------------------------*)
-
- crc_sw := bin_xfer <> bin_xmodem;
- batch_sw := bin_xfer = bin_ymodem_batch;
- ymodem_sw := (bin_xfer = bin_ymodem_batch) OR (bin_xfer = bin_ymodem);
-
- curr_size := 0;
-
- IF active_port^.port_type <> port_modem THEN
- time_to_wait := active_port^.time_out
- ELSE
- time_to_wait := 10;
-
- (*-----------------------------------------------------------------------*)
- (* Do the transfer *)
- (*-----------------------------------------------------------------------*)
-
- set_binary_switch(TRUE);
-
- IF up_it THEN
- xy_upload
- ELSE
- xy_download(FALSE);
-
- (*-----------------------------------------------------------------------*)
- (* Close the file *)
- (*-----------------------------------------------------------------------*)
-
- get_semaphore(semaphore_interrupts, sem_exclusive, FALSE);
- {$I-}
- CLOSE(data_file^);
- b_size := IORESULT;
- {$I+}
- free_semaphore(semaphore_interrupts);
-
- (*-----------------------------------------------------------------------*)
- (* Do batch ending data *)
- (*-----------------------------------------------------------------------*)
-
- IF batch_sw THEN
- IF up_it THEN
- get_a_block
- ELSE
- xy_download(TRUE);
-
- (*-----------------------------------------------------------------------*)
- (* Clear the binary switch *)
- (*-----------------------------------------------------------------------*)
-
- set_binary_switch(FALSE);
-
- (*-----------------------------------------------------------------------*)
- (* Free the buffer area *)
- (*-----------------------------------------------------------------------*)
-
- free_task_mem('BIN', TRUE);
-
- END;